package com.colorful.insuranceproject.request;

import android.os.Handler;

import com.colorful.insuranceproject.adapter.CityListBean;
import com.colorful.insuranceproject.bean.AboutClaimsProgressBean;
import com.colorful.insuranceproject.bean.ClaimsDetailsBean;
import com.colorful.insuranceproject.bean.PhysicalExaminationAppointmentBean;
import com.colorful.insuranceproject.bean.UploadDetailsBean;
import com.colorful.insuranceproject.bean.UploadRecordBean;
import com.colorful.insuranceproject.consts.URLConst;
import com.lovely3x.common.requests.impl.HandlerRequestImpl;
import com.lovely3x.common.utils.ALog;
import com.lovely3x.common.utils.Response;
import com.lovely3x.jsonparser.model.JSONObject;

import okhttp3.OkHttpClient;

/**
 * Created by handsome-Bob on 2017/8/18.
 * <p>
 * 理赔板块的请求器
 */
public class ClaimsRequest extends BaseRequest {
    public ClaimsRequest(Handler handler) {
        super(handler);
    }

    /**
     * 获取上传记录
     *
     * @param currentIndex 页面
     * @param what         handler传递值
     */
    public void getUploadRecord(final int currentIndex, int what) {
        process(new ProcessResultExtension() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取上传记录---------------->" + result);
                    res.obj = result.getJSONArray(DATA_KEY).createObjects(UploadRecordBean.class);
                }
            }

            @Override
            public void onRequestBefore(Response res, OkHttpClient client) {
                res.addtional = currentIndex;
            }
        }, URLConst.GET_UPLOAD_RECORD_URL, what, "page", currentIndex, "pageLength", 10);
    }

    /**
     * 理赔进度
     *
     * @param currentIndex 页面
     * @param what         handler传递值
     */
    public void getClaimsProgress(final int currentIndex, int what) {
        process(new ProcessResultExtension() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "理赔进度---------------->" + result);
                    res.obj = result.getJSONArray(DATA_KEY).createObjects(AboutClaimsProgressBean.class);
                }
            }

            @Override
            public void onRequestBefore(Response res, OkHttpClient client) {
                res.addtional = currentIndex;
            }
        }, URLConst.GET_CLAIMS_PROGRESS_URL, what, "page", currentIndex, "pageLength", 10);
    }

    /**
     * 理赔详情
     *
     * @param id   理赔ID
     * @param what handler
     */
    public void getClaimsDetails(String id, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    res.obj = result.getJSONObject(DATA_KEY).createObject(ClaimsDetailsBean.class);
                    ALog.e(TAG, "理赔详情----------------------->" + result);
                }
            }
        }, URLConst.GET_CLAIMS_DETAILS_URL, what, "insuranceId", id);
    }

    /**
     * 数据上传第二步
     *
     * @param time      时间
     * @param money     金额
     * @param listOne   发票
     * @param listTwo   其他
     * @param listThree 其他
     * @param what      handler 传递值
     */
    public void paperUpload(String time, String money, String listOne, String listTwo, String listThree, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "数据上传第二步---------------------->" + result);
                    res.obj = result.getJSONObject(DATA_KEY);
                }
            }
        }, URLConst.PAPER_UPLOAD_URL, what, "paperTime", time, "applyMoney", money, "paperImgs1", listOne, "paperImgs2", listTwo, "paperImgs3", listThree);
    }

    /**
     * 撤销理赔
     *
     * @param insuranceId 理赔ID
     * @param what        handler
     */
    public void cancelClaimsUrl(String insuranceId, int what) {
        process(new HandlerRequestImpl.EmptyProcessResult(), URLConst.CANCEL_CLAIMS_URL, what, "insuranceId", insuranceId);
    }

    /**
     * 获取历史上传理赔的详情
     *
     * @param insuranceId 理赔ID
     * @param what        handler
     */
    public void getUploadDetails(String insuranceId, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取历史上传理赔的详情----------------------->" + result);
                    res.obj = result.getJSONObject(DATA_KEY).createObject(UploadDetailsBean.class);
                }
            }
        }, URLConst.GET_UPLOAD_DETAILS_URL, what, "insuranceId", insuranceId);
    }

    /**
     * 编辑或者补充历史上传
     */
    public void supplementUpload(String insuranceId, String money, String time, String stringOne, String stringTwo, String stringThree, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "编辑或者补充历史上传---------------------->" + result);
                    res.obj = result.getJSONObject(DATA_KEY);
                }
            }
        }, URLConst.SUPPLEMENT_UPLOAD_URL, what, "insuranceId", insuranceId, "paperTime", time, "applyMoney", money, "paperImgs1", stringOne, "paperImgs2", stringTwo, "paperImgs3", stringThree);
    }

    /**
     * 获取体检预约
     *
     * @param what handler
     */
    public void getPhysicalExaminationAppointmentData(String areaId, int isChild, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取体检预约----------------->" + result);
                    res.obj = result.getJSONArray(DATA_KEY).createObjects(PhysicalExaminationAppointmentBean.class);
                }
            }
        }, URLConst.GET_PHYSICAL_EXAMINATION_APPOINTMENT_URL, what, "areaId", areaId, "isChild", isChild);

    }

    /**
     * 获取体检预约详情
     *
     * @param reserveId 预约ID
     * @param what      handler
     */
    public void getPhyDetailsUrl(String reserveId, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取体检预约详情-----------------》" + result);
                    res.obj = result.getJSONObject(DATA_KEY).createObject(PhysicalExaminationAppointmentBean.class);
                }
            }
        }, URLConst.GET_PHY_DETAILS_URL, what, "reserveId", reserveId);
    }

    /**
     * 获取城市列表
     *
     * @param cityId 城市ID
     * @param what   handler
     */
    public void getCityList(String cityId, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取城市列表----------------->" + result);
                    res.obj = result.getJSONArray(DATA_KEY).createObjects(CityListBean.class);
                }
            }
        }, URLConst.GET_CITY_LIST_URL, what, "cityId", cityId);
    }
}
